﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using TaoPortal.BusinessLogic.Extensions;
using TaoPortal.BusinessLogic.Repository;
using TaoPortal.Common.Utility;
using TaoPortal.Entity;

namespace TaoPortal.Areas.Admin.Models
{
    public class AdSearcher
    {
        public string AdID { get; set; }
        public string AdName { get; set; }
    }

    public class AdModel : BaseModel
    {
        public AdSearcher Searcher { get; set; }
        public AdEntity Entity { get; set; }
        public string AdTypeList { get; set; }

        public AdModel()
        {
            Searcher = new AdSearcher();
        }

        public PagedList<TP_SysAd> GetList()
        {
            var rp = new SystemRepository();
            var data = rp.GetAdList(Searcher.AdID, Searcher.AdName, PageIndex, PageSize);
            foreach (var item in data)
            {
                item.Status = Common.SysEnum.ConvertValue<Common.SysEnum.AdStatus>(item.Status);
            }
            return data;
        }

        public void Add()
        {
            var rp = new SystemRepository();
            rp.AddAd(new TP_SysAd
            {
                ID = Guid.NewGuid().ToString(),
                Status = Entity.Status,
                AdContent = Entity.AdContent,
                AdName = Entity.AdName,
                AdType = Entity.AdType
            });
        }

        public void Edit()
        {
            var rp = new SystemRepository();
            rp.UpdateAd(new TP_SysAd
            {
                ID = Entity.ID,
                Status = Entity.Status,
                AdContent = Entity.AdContent,
                AdName = Entity.AdName,
                AdType = Entity.AdType
            });
        }

        public void Delete(string id)
        {
            var rp = new SystemRepository();
            rp.DeleteAd(id);
        }

    }

    public class AdEntity
    {
        public string ID { get; set; }
        public string AdName { get; set; }
        public string AdType { get; set; }
        public string AdContent { get; set; }
        public string Status { get; set; }
    }

}